package com.kaishengit.service;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.dao.TaskDao;
import com.kaishengit.pojo.Task;
import com.kaishengit.pojo.TaskType;
import com.kaishengit.pojo.User;

@Transactional
public class TaskService {
 private TaskDao taskDao;
 
public TaskDao getTaskDao() {
	return taskDao;
}

public void setTaskDao(TaskDao taskDao) {
	this.taskDao = taskDao;
}

public void save(Task task) {
	
	taskDao.save(task);
	
	
}

public List<Task> findAll(User u) {
	
	/*Pager<Task> pager=new Pager<Task>(num,taskDao.getCounts());*/
String hql=" select h from Task as h where h.user.id=? and h.enables=?";
return taskDao.find(hql,u.getId(),true);	
}

public List<Task> findsuc() {
	
	return taskDao.findBy("complete",true);
}

public List<Task> findfalse() {
	String hql=" select h from Task as h where h.complete=? and h.enables=?";
	return taskDao.find(hql, false,true);
}

public List<Task> findByType(TaskType taskType) {
	// TODO Auto-generated method stub
return taskDao.findByid(taskType);
}

public Task findByid(String taskid) {
	
	return taskDao.get(taskid);
}

public List<Task> findAlls(User u, int startIndex) {
	String hql=" select h from Task as h where h.user.id=? and h.enables=?";
	return taskDao.findpagerTask(hql,startIndex,u.getId(),true);	

}


 
}
